<template>
  <div class="box4" v-if="singer">
    <div class="bg1">
      <!-- 头部导航 -->
      <div class="topheader">
        <div class="img">
          <!-- 背景 -->
          <img :src="singer.user.backgroundUrl" alt="" />
        </div>
        <div class="button" @click="$router.go(-1)">
          <span class="iconfont icon-fanhui"></span>
        </div>
      </div>
    </div>
    <div class="musicList">
      <!-- 详情信息 -->
      <div class="boxtext">
        <!-- 头像 -->
        <div class="img">
          <img :src="singer.user.avatarUrl" alt="" />
        </div>
        <div class="details">
          <!-- 昵称 -->
          <div class="textname">{{ singer.artist.name }}</div>
          <!-- 粉丝 -->
          <div class="fens">
            <div class="top">
              <span class="gang">661.5万<span>粉丝</span></span
              ><span>Lv2</span>
            </div>
            <div class="bottom">{{ singer.identify.imageDesc }}</div>
          </div>
          <!-- 关注 -->
          <div class="guanz">
            <span @click="isfolloweds"  v-show="isfollowed==false" class="left">+关注</span>
            <span @click="isfolloweds" style="background:#999" v-show="isfollowed==true" class="left">已关注</span>
            <!-- <span class="right">V</span> -->
          </div>
        </div>
      </div>
    </div>
    <!-- 切换信息 -->
    <div class="topkeas">
      <div @click="fase = 1" :class="fase == 1 ? 'text' : ''">主页</div>
      <div @click="fase = 2" :class="fase == 2 ? 'text' : ''">歌曲</div>
      <!-- <div @click="fase = 3" :class="fase == 3 ? 'text' : ''">专辑</div>
      <div @click="fase = 4" :class="fase == 4 ? 'text' : ''">动态</div> -->
      <div @click="fase = 5" :class="fase == 5 ? 'text' : ''">视频</div>
    </div>
    <!-- 主页详情 -->
    <div v-show="fase == 1" class="textdetails" v-if="describe">
      <div class="div tops">艺人百科</div>
      <div class="div name">
        <span>{{ singer.identify.imageDesc }}</span>
      </div>
      <div class="div artistname">
        艺人名:<span>{{ singer.user.nickname }}</span>
      </div>
      <div class="div identity">
        身份:
        <span
          v-for="(item, index) in singer.secondaryExpertIdentiy"
          :key="index"
          >{{ item.expertIdentiyName }}</span
        >
      </div>
      <div class="div motto">
        <span>{{ singer.user.signature }}</span>
      </div>
      <div class="div autobiographical">
        个人简介:<p>&nbsp;&nbsp;{{ describe.briefDesc }}</p>
      </div>
    </div>
    <!-- 歌手歌单 -->
    <div v-show="fase == 2" class="textdetails">
      <div
        v-for="(item, index) in singerlist"
        @click="setId(item.id)"
        :key="item.id"
        class="lidttext"
      >
        <div class="left">{{ index + 1 }}</div>
        <div class="right">
          <div class="top">{{ item.name }}</div>
          <div class="bottom">{{ item.ar[0].name }}</div>
        </div>
      </div>
    </div>
    <!-- 歌手mv -->
    <div v-show="fase == 5" class="textdetails">
      <div v-for="(item, index) in mvs" :key="index" class="videolists"
      >
        <router-link class="img" tag="div" :to="'/mvsublist?id=' + item.id">
          <img
            :src="item.imgurl"
            alt=""
          />
        </router-link>
        <div class="videoright">
          <div class="videoname">{{ item.name }}</div>
          <div class="videotime">{{ item.publishTime }}</div>
          <div class="videotime">{{item.playCount | playCountData}}播放</div>
        </div>
      </div>
      <div v-show="!mvs.length" class="videolists">
        <div class="tishi">TA暂时还没有MV</div>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from "vant";
import {
  getArtistDetail,
  getArtistDesc,
  getArtist,
  getArtistMv,
} from "../../api/singer";
export default {
  data() {
    return {
      videoId: null, //歌手id
      singer: null, //歌手详情
      describe: null, //歌手描述
      fase: 1, //判断
      singerlist: [], //歌手单曲列表
      mvs: [], //歌手mv列表
      isfollowed:false,//关注判断
    };
  },
  created() {
    let queryId = this.$route.query;
    this.videoId = queryId.id;
    if (!("id" in queryId)) {
      this.$router.push("/singer");
    }
    console.log(queryId);
    // 歌手详情
    getArtistDetail({ id: this.videoId }).then((data) => {
      this.singer = data.data;
      console.log(this.singer);
    });
    // 歌手描述
    getArtistDesc({ id: this.videoId }).then((data) => {
      this.describe = data;
    });
    // 歌手单曲
    getArtist({ id: this.videoId }).then((data) => {
      console.log(data);
      this.singerlist = data.hotSongs;
    });
    // 获取歌手 mv
    getArtistMv({ id: this.videoId }).then((data) => {
      console.log(data);
      this.mvs = data.mvs;
    });
  },
  methods: {
    setId(id) {
      console.log(id);
      this.$emit("get-player-id", id);
    },
    // 关注判断
    isfolloweds(){
      this.singer.user.followed = !this.singer.user.followed;
      this.isfollowed = !this.isfollowed
      if(!this.isfollowed){
         Toast({
          message: "取消关注",
          position: "bottom",
          duration: 500,
        });
      }else{
        Toast({
          message: "关注成功",
          position: "bottom",
          duration: 500,
        });
      }
    }
  },
  filters: {
    playCountData(value) {
      let w = value > 10000 ? value / 10000 : value; //万计算
      let y = w > 10000 ? parseInt(value / 10000) + "亿" : parseInt(w) + "万";
      return y;
    },
  },
};
</script>

<style lang="less">
.box4 {
  background: #f5f5f5;
  height: 100%;
  padding-bottom: 20px;
  .bg1 {
    .topheader {
      position: relative;
      height: 270px;
      .icon-fanhui{
        font-size: 25px;
      }
      .img {
        width: 100%;
        height: 270px;
        position: relative;
        img {
          position: absolute;
          top: 0px;
          left: 0px;
          right: 0px;
          bottom: 0px;
          margin: auto;
          width: 100%;
        }
      }
      .title {
        font-size: 18px;
        position: absolute;
        left: 18px;
        bottom: 18px;
        color: #fff;
      }
      .button {
        font-size: 18px;
        position: absolute;
        left: 12px;
        top: 12px;
        color: #fff;
      }
    }
    .vohi {
      width: 100%;
      height: 40%;
      overflow: hidden;
      .bg {
        width: 100%;
        height: 100%;
        // background-size: 100% !important;
        transform: scale(1);
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  .musicList {
    background-color: #f5f5f5;
    width: 100%;
    border-radius: 7px;
    position: relative;
    top: 7px;
    padding-bottom: 50px;
    .boxtext {
      width: 90%;
      height: 220px;
      position: absolute;
      top: 125px;
      bottom: 0px;
      left: 0px;
      right: 0px;
      margin: auto;
      background-color: #ffffffe6;
      border-radius: 10px;
      .details {
        width: 100%;
        padding-top: 55px;
        display: flex;
        flex-direction: column;
        align-items: center;
        div {
          margin: 5px 0;
          text-align: center;
        }
        .textname {
          font-size: 20px;
          color: black;
        }
        .fens {
          .top {
            span {
              padding: 0 5px;
              font-size: 14px;
              color: #999;
            }
            .gang {
              border-right: 1px solid #999;
            }
          }
          .bottom {
            padding-top: 10px;
            font-size: 14px;
            color: #999;
          }
        }
        .guanz {
          .left {
            margin: 0 10px;
            display: inline-block;
            padding: 10px 20px;
            border-radius: 40px;
            font-size: 14px;
            line-height: 14px;
            color: white;
            background: red;
          }
          .right {
            padding: 10px;
            border-right: 50%;
            font-size: 14px;
            line-height: 14px;
            width: 14px;
            height: 14px;
            border-radius: 50%;
            border: 1px solid #999;
            display: inline-block;
            color: #999;
          }
        }
      }
      .img {
        width: 100px;
        height: 100px;
        margin: 0 auto;
        position: absolute;
        top: -50px;
        left: calc(100% / 2 - 50px);
        img {
          widows: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }
    }
  }
  .topkeas {
    width: 100%;
    padding-top: 160px;
    display: flex;
    justify-content: space-around;
    margin: 10px 0px;
    div {
      font-size: 16px;
      color: #999;
    }
    .text {
      color: black;
      font-weight: 800;
    }
  }
  .textdetails {
    width: 90%;
    border-radius: 15px;
    background-color: white;
    margin: 10px auto;
    padding-bottom: 50px;
    .lidttext {
      display: flex;
      width: 100%;
      padding-top: 20px;
      .left {
        flex: 0 0 44px;
        line-height: 53px;
        text-align: center;
        font-size: 16px;
        color: #6d6e6e;
      }
      .right {
        width: 100%;
        border-bottom: 1px solid #e4e4e4;
        .top {
          padding-top: 5px;
          font-size: 16px;
          color: #1b1c1c;
          height: 22px;
          overflow: hidden;
          font-size: 500;
        }
        .bottom {
          font-size: 12px;
          color: #929393;
        }
      }
    }
    .div {
      padding: 10px 20px;
      font-size: 14px;
      color: #999;
    }
    .tops {
      font-size: 18px;
      color: black;
      font-weight: 800;
    }
    .name {
      span {
        color: #5f5d5d;
      }
    }

    .artistname {
      span {
        margin: 0 7px;
        color: #5f5d5d;
      }
    }
    .identity {
      span {
        margin: 0 7px;
        color: #5f5d5d;
      }
    }
    .motto {
      span {
        color: #5f5d5d;
      }
    }
    .autobiographical {
      p {
        color: #5f5d5d;
      }
    }
    .videolists {
      width: 335px;
      padding: 10px 10px 0px 10px;
      display: flex;
      .tishi{
        width: 100%;
        height: 106px;
        color: brown;
        font-size: 20px;
        line-height: 100px;
        text-align: center
      }
      .img {
        width: 150px;
        height: 90px;
        border-radius: 10px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
      }
    }
    .videoright {
      margin-left: 10px;
      .videoname {
        font-size: 16px;
        color: #565656;
        padding: 10px 0px 10px 0px;
        font-weight: 600;
        width: 170px;
        height: 9px;
        overflow: hidden;
      }
      .videotime {
        padding-top: 5px;
        color: #999;
        font-size: 12px;
      }
    }
  }
}
</style>